// Toast组件
import React from 'react';
import ReactDOM from 'react-dom';

class Toast extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            message: '',
            time: 0
        };
    }

    show(message, time) {
        this.setState({ message, time });
        setTimeout(() => {
            this.setState({ message: '', time: 0 });
        }, this.state.time); // 3秒后自动隐藏
    }

    render() {
        return ReactDOM.createPortal(
            <div className="toast">
                {this.state.message}
            </div>
        )
    }
}

export default Toast;
